<%-- 
    Document   : manage_edit
    Created on : Oct 24, 2011, 8:40:26 AM
    Author     : Yudi Retanto
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="/header.jsp"></jsp:include>
<h1>
    Tambah Jadwal Keberangkatan
</h1>
<script type="text/javascript">
    $(function() {
        $( "#iDate" ).datepicker({ dateFormat: "yy/mm/dd" });
    });
</script>
<form action="./flights?action=manage&mode=edit&schedule=${schedule.getID()}" method="post" onsubmit="return submit();">
<table id="manageForm">
    <tr>
        <td style="width: 20%;">
            <label for="cityFrom">Airport Keberangkatan :</label>
        </td>
        <td>
            <select id="sAirportFrom" name="airportFrom">
                <c:forEach items="${airports}" var="airport">
                    <option <c:if test="${schedule.getOriginID() == airport.getID()}">selected="selected"</c:if> value="${airport.getID()}">${airport.getName()}</option>
                </c:forEach>
            </select>
        </td>
    </tr>
    <tr>
        <td style="width: 20%;">
            <label for="cityTo">Airport Tujuan :</label>
        </td>
        <td>
            <select id="sAirportTo" name="airportTo" >
                <c:forEach items="${airports}" var="airport">
                    <option <c:if test="${schedule.getDestinationID() == airport.getID()}">selected="selected"</c:if> value="${airport.getID()}">${airport.getName()}</option>
                </c:forEach>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <label for="airline">Maskapai Penerbangan :</label>
        </td>
        <td>
            <select name="airline">
                <c:forEach items="${airlines}" var="airline">
                    <option <c:if test="${schedule.getAirlineID() == airline.getID()}">selected="selected"</c:if> value="${airline.getID()}">${airline.getName()}</option>
                </c:forEach>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <label for="class">Kelas Penerbangan :</label>
        </td>
        <td>
            <select name="class">
                <c:forEach items="${classes}" var="clas">
                    <option <c:if test="${schedule.getClassID() == clas.getID()}">selected="selected"</c:if> value="${clas.getID()}">${clas.getName()}</option>
                </c:forEach>
            </select>
        </td>
    </tr>
    <tr>
        <td style="width: 20%;">
            <label for="name">Tanggal Keberangkatan :</label>
        </td>
        <td>
            <input type="text" name="date" id="iDate" value="${schedule.getDate()}"/>
        </td>
    </tr>
    <tr>
        <td>
            <label for="hour">Waktu Keberangkatan :</label>
        </td>
        <td>
            <c:set var="time" value="${schedule.getHour()}" />
            <select name="hour">
                <%
                    String time = (String) pageContext.getAttribute("time");
                    String hour = time.split(":")[0];
                    for(int i=0;i<24;i++){
                        if(hour.equals(String.format("%02d", i))){
                            out.println("<option selected=\"selected\" value=\""+String.format("%02d", i) +"\">"+String.format("%02d", i)+"</option>");
                        } else {
                            out.println("<option value=\""+String.format("%02d", i) +"\">"+String.format("%02d", i)+"</option>");
                        }
                    }
                %>
            </select><span> : </span>
            <select name="minute">
                <%
                    String minute = time.split(":")[1];
                    for(int i=0;i<60;i++){
                        if(minute.equals(String.format("%02d", i))){
                            out.println("<option selected=\"selected\" value=\""+String.format("%02d", i) +"\">"+String.format("%02d", i)+"</option>");
                        } else {
                            out.println("<option value=\""+String.format("%02d", i) +"\">"+String.format("%02d", i)+"</option>");
                        }
                    }
                %>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <label for="fare">Harga Tiket :</label>
        </td>
        <td>
            <input type="text" name="fare" value="${schedule.getFare()}"/>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="Submit" />
            <input type="hidden" name="id" value="${schedule.getID()}" />
        </td>
    </tr>
</table>
</form>
<jsp:include page="/footer.jsp"></jsp:include>
